/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.account;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.account.SysRoleUser;
import com.unis.service.account.SysRoleUserService;

/**
 * @author CSJ (email:raulcsj@163.com)
 * @since 2012-12-10
 */
@Controller
@RequestMapping("/sysroleuser")
public class SysRoleUserController {

    private SysRoleUserService sysroleuserService;

    /****************************************
     * Insert a instace of SysRoleUser
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertSysRoleUser(@RequestBody List<?> sysroleuserList) throws Exception {
        String status = "failure";
        sysroleuserService.batchInsert(sysroleuserList);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of SysRoleUser
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody SysRoleUser sysroleuser) throws Exception {
        sysroleuser.setStatmentId("SysRoleUser.update");
        String status = "failure";
        sysroleuserService.update(sysroleuser);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of SysRoleUser
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody SysRoleUser sysroleuser) throws Exception {
        sysroleuser.setStatmentId("SysRoleUser.delete");
        String status = "failure";
        sysroleuserService.batchDelete(sysroleuser);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of SysRoleUser
     ****************************************/
    @RequestMapping("/queryAsList/{type}")
    @ResponseBody
    public Object queryAsList(@PathVariable String type, HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        paramMap.put("type", type);
        SysRoleUser sysroleuser = new SysRoleUser();
        sysroleuser.setStatmentId("SysRoleUser.queryAsList");
        BeanUtils.populate(sysroleuser, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(sysroleuser, pageMap);
        List<BaseModel> sysroleuserList = sysroleuserService.queryAsList(sysroleuser);
        Map<String, Object> renderMap = GridUIMapper.render(sysroleuser, sysroleuserList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of SysRoleUser
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody SysRoleUser sysroleuser) throws Exception {
        sysroleuser.setStatmentId("SysRoleUser.queryAsObject");
        return sysroleuserService.queryAsObject(sysroleuser);
    }

    @RequestMapping("/roleUserMgr")
    public String roleUserMgr() {
        return "sys/sysroleuserList";
    }

    @Resource
    public void setSysRoleUserService(SysRoleUserService sysroleuserService) {
        this.sysroleuserService = sysroleuserService;
    }
}
